using System;
using System.Collections.Generic;
using System.Xml;
using TALoaders;
using TAAlert.CommonUtils;

namespace TAAlert.Alerts
{
    public abstract class Alert
    {
        #region Private Members
        private static readonly string LOADER_XML = "loader";
        private static readonly string TICKER_XML = "ticker";
        private string tickerM;
        protected BaseLoader loaderM;
        private StrategyName xmlNameM;
        #endregion

        protected Alert(XmlReader r, StrategyName xmlName)
        {
            r.ReadStartElement();
            string loaderName = r.ReadElementContentAsString(LOADER_XML, "");
            this.loaderM = DownloaderFactory.createCachedDownloader(loaderName);

            this.Ticker = r.ReadElementContentAsString(TICKER_XML, "");
            this.xmlNameM = xmlName;
        }
        protected Alert(BaseLoader loader, string ticker, StrategyName xmlName)
        {
            this.loaderM = loader;
            this.Ticker = ticker;
            this.xmlNameM = xmlName;
        }

        #region Public Methods / Interface
        public string Ticker
        {
            get { return tickerM; }
            private set { tickerM = value; }
        }
        public StrategyName XmlName
        {
            get { return xmlNameM; }
            private set { this.xmlNameM = value; }
        }

        public abstract Signal evalAlert(out string[] info);     // Latest alert + detailed information
        public abstract Signal oldAlert();      // Yesterday's alert

        public virtual void writeXml(XmlWriter writer)
        {
            writer.WriteElementString(LOADER_XML, loaderM.Loader.ToString());
            writer.WriteElementString(TICKER_XML, Ticker);
        }
        public abstract string Description { get; }
        #endregion
    }
}
